using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Dll.Essences;
using Dll.DAL;
using Dll;

namespace Price_Guide
{
    public partial class CloseConnectionForm : Form
    {
        List<int> pListID = new List<int>();
        bool init;
        public CloseConnectionForm()
        {
            InitializeComponent();
            List<Providers> pList = ProvidersDAL.GetAllProvidersListWithPath();
            int n = 0;
            bool f;
            init = true;
            for (int i = 0; i < pList.Count; i++)
            {
                f = ProvidersConnection.ExistsConnection(pList[i].Id);
                if(f)
                {
                    treeView1.Nodes.Add(pList[i].Name);
                    treeView1.Nodes[n].Checked = true;
                    n++;
                    pListID.Add(pList[i].Id);
                }
            }
            init = !true;
        }

        private void treeView1_BeforeCheck(object sender, TreeViewCancelEventArgs e)
        {
            if (init)
                return;
            if (e.Node.Checked)
                ProvidersConnection.CloseConnection(pListID[e.Node.Index]);
            else
                e.Cancel=true;
        }
    }
}